﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model.Course;
using Model.User;
using System.Web.UI.HtmlControls;

public partial class ViewTask : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["CourseId"] == null) return;

        if (Teacher.get(Convert.ToInt32(Session["Person"])) != null)
            toolbarButtonAddTask.Visible = true;

        Course c = Course.get(Convert.ToInt32(Session["CourseId"]));

        if (c != null)
        {
            courseNameLabel.Text = c.getName();
            courseNameLabel.Font.Size = FontUnit.Parse("1.5em");
            lecturerLabel.Text = "Prowadzący: " + c.getLecturer().getFirstName() + " " + c.getLecturer().getLastName();

            Task[] task = Task.getTasks(c);

            foreach (Task t in task)
            {
                LinkButton taskButton = new LinkButton();

                taskButton.Text = t.getName();
                taskButton.CommandArgument = t.getId().ToString();
                taskButton.Command += lectureButton_Command;


                LecturesContent.Controls.Add(taskButton);
                LecturesContent.Controls.Add(new HtmlGenericControl("br"));
            }
        }
    }

    void lectureButton_Command(object sender, CommandEventArgs e)
    {
        Session["TaskId"] = e.CommandArgument;
        Session["ActiveMenuButton"] = "menuButton6";
        Response.Redirect("~/CourseView/ViewTask.aspx");
    }

    protected void toolbarButtonAddLecture_Command(object sender, CommandEventArgs e)
    {
        Session["ActiveMenuButton"] = "menuButton6";
        Response.Redirect((string)e.CommandArgument);
    }
}